# 1. 导包
import requests

# 2. 发送获取验证码的http请求， 获取 cookie(包含着令牌)
resp_verify = requests.get(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify&r=0.7794573621727154")
print("查看cookies：", resp_verify.cookies)

# 3. 从 返回的 resp 中获取 cookie
my_cookie = resp_verify.cookies

# 4. 发送http 登录请求, 携带 cookie，获取响应结果
resp = requests.post(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login&t=0.4003948083916662",
              headers={"Content-Type":"application/x-www-form-urlencoded"},
              data={"username":"13812345678", "password":"123456", "verify_code":"8888"},
              cookies=my_cookie)  # 代表已经成功发送获取验证码

# 5. 打印响应结果
# print("打印文本响应结果：", resp.text)
print("打印json响应结果：", resp.json())